using System.Collections;
using KB;
using System;
namespace TestKooboo.Bizs
{
    public class BizContext
    {
        public static BizContext Current
        {
            get
            {
                return ContextUtility.GetOrAdd<BizContext>("BizContext", () => new BizContext());
            }
        }
		private readonly Hashtable _services = new Hashtable();

		public ArticleBiz ArticleBiz
        {
            get
            {
                return GetBiz<ArticleBiz>();
            }
        }
		public CategoryBiz CategoryBiz
        {
            get
            {
                return GetBiz<CategoryBiz>();
            }
        }
		public CommentBiz CommentBiz
        {
            get
            {
                return GetBiz<CommentBiz>();
            }
        }
		public TestImageBiz TestImageBiz
        {
            get
            {
                return GetBiz<TestImageBiz>();
            }
        }

        public T GetBiz<T>() where T : class
        {
            Type serviceType = typeof(T);
            if (!_services.ContainsKey(serviceType))
            {
                T service = Activator.CreateInstance<T>();
                _services.Add(serviceType, service);
            }
            return (T)_services[serviceType];
        }
    }
}
